package com.manger.thread;

import com.alibaba.fastjson.JSONObject;
import com.manger.chrome.DriverManger;
import com.manger.utils.DataTools;
import com.manger.utils.RemoteExecute;

import java.io.IOException;

/**
 * @ClassName HeartBeatThread
 * @Description TODO
 * @Author @LiuHongJun
 * @Date 2025-10-23 13:37
 * @Version 1.0
 */
public class HeartBeatThread extends Thread {

    private int connectState = 1;
    public void run() {
        try{
            Thread.sleep(20000);
        }catch (Exception e){

        }
        while (DriverManger.hasOnline()) {
            try{
                System.out.println("=========HeartBeatThread=============");
                String url = DataTools.baseUrl + "/proxy/heartBeat"
                        + "?loginUserId=" + DataTools.loginUserId + "&useProxyId=" + DataTools.useProxyId
                        + "&connectState=" + connectState;
                JSONObject jsonObject = RemoteExecute.execute(url);
                Thread.sleep(10 * 1000);
                connectState = 1;
            }catch (InterruptedException e){
                break;
            }catch (Exception e){
                connectState = 0;
                System.out.println("链接服务器失败！");
                try{
                    Thread.sleep(10 * 1000);
                }catch (Exception e2){
                    e2.printStackTrace();
                }
            }
        }
    }


}
